-- $Id: xpa-net-sck.ads,v 1.8 2006-01-01 05:24:05 bacon Exp $

with gnat.sockets;
with ada.streams;

package xpa.net.sck is

	type sck_type is private;
	type sck_access is access all sck_type;

	subtype addr_type is gnat.sockets.sock_addr_type;
	subtype family_type is gnat.sockets.family_type;
	subtype mode_type is gnat.sockets.mode_type;
	type data_type is (binary, text);
	
	inet4: constant family_type := gnat.sockets.family_inet;	
	inet6: constant family_type := gnat.sockets.family_inet6;

	stream: constant mode_type := gnat.sockets.socket_stream;	
	datagram: constant mode_type := gnat.sockets.socket_datagram;

	procedure open (sck: in out sck_access; 
		family: in family_type; mode: in mode_type);

	procedure close (sck: in out sck_access);

	procedure set_connect_timeout (
		sck: in out sck_access; timeout: in duration);
	procedure set_accept_timeout (
		sck: in out sck_access; timeout: in duration);
	procedure set_receive_timeout (
		sck: in out sck_access; timeout: in duration);
	procedure set_send_timeout (
		sck: in out sck_access; timeout: in duration);

	procedure bind (sck: in out sck_access; server: in out addr_type);
	procedure connect (sck: in out sck_access; server: in out addr_type);
	procedure listen (sck: in out sck_access; length: in positive := 15);

	procedure receive (sck: in out sck_access;
		item: out ada.streams.stream_element_array; 
		last: out ada.streams.stream_element_offset);
	--procedure receive (
	--	sck: in out sck_access; item: out wchar; last: out positive);

	procedure send (sck: in out sck_access;
		item: in ada.streams.stream_element_array; 
		last: out ada.streams.stream_element_offset);

private

	type sck_type is
	record
		handle: gnat.sockets.socket_type;
		connect_timeout: duration := -1.0;
		accept_timeout: duration := -1.0;
		send_timeout: duration := -1.0;
		receive_timeout: duration := -1.0;
		dynamic: boolean := false;
	end record;

end xpa.net.sck;
